package web;

import pojo.SmbmsProvider;
import service.SmbmsProviderService;
import service.impl.SmbmsProviderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/providerView")
public class ShowProviderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        this.doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
//从页面获取ID
        String id=req.getParameter("id");
        Long ids=0L;
        if(id != null){
            ids=Long.parseLong(id);
        }
//调用业务层接口
        SmbmsProviderService smbmsProviderService=new SmbmsProviderServiceImpl();
        try {
            SmbmsProvider smbmsProvider = smbmsProviderService.queryProviderById(ids);
            if(null != smbmsProvider){
//把对象放在request作用域中
                req.setAttribute("p",smbmsProvider);
                req.getRequestDispatcher("providerView.jsp").forward(req,resp);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
